import axios from 'axios';
//配置项
const httpFetch = axios.create({
    baseURL:'http://cangdu.org:8001',
    timeout:10000
});
// 设置post请求头
httpFetch.defaults.headers.post['Content-Type'] = 'application/json;charset=utf-8'; 
//请求拦截
httpFetch.interceptors.request.use(config=>{
    // 可以对发起请求时，查看token是否存在以及过期
    // 过期的话 。路由到 /login 页面
    console.log('拦截请求')
    return config;
},error=>Promise.error(error))
// 响应拦截
httpFetch.interceptors.response.use(resp=>{
    console.log('拦截返回')
    if(resp.status === 200){
        return Promise.resolve(resp.data);
    }else{
        return Promise.reject(resp)
    }
},error=>Promise.reject(error))
export default httpFetch;


/** https://www.jianshu.com/p/df464b26ae58/
 get 请求
    axios('/user/12345');
    axios({
        method:'get',
        url:'http://bit.ly/2mTM3nY',
        
    })
    axios.get('/user?ID=12345')
    axios.get('/user',{
            params:{
                ID:12345
            }
        })

 post 请求
    axios.post('/user',{
            firstName:'Fred',
            lastName:'Flintstone'
        })

    axios({
        method:"POST",
        url:'/user/12345',
        data:{
            firstName:"Fred",
            lastName:"Flintstone"
        }
    });
 */